package com.yc.spring;

import com.yc.spring.bean.Color;
import com.yc.spring.bean.HelloBean;
import org.springframework.context.annotation.*;

// beans.xml
@Configuration
public class IocConfig {

    // @Bean ==> <bean>
    @Bean({"hello","a","b"}) // id
    public HelloBean hello(){
        return new HelloBean();
    }

    @Bean // 没有指定 id ,则方法名就是id
    @Primary
    public HelloBean hello1(){
        return new HelloBean("张三", 18);
    }

    @Bean // 没有指定 id ,则方法名就是id
    @Lazy
    @Scope("prototype")
    public HelloBean hello2(){
        HelloBean helloBean = new HelloBean();
        helloBean.setName("李四");
        helloBean.setAge(10);
        helloBean.setGender('女');
        return helloBean;
    }

    @Bean
    Color color(){
        Color color = new Color();
        color.setColor("red");
        return color;
    }

    @Bean("hello3") // Bean 方法的参数, Spring会自动从容器中获取bean 注入
    // 方法参数注入 => 接口注入
    public HelloBean hello3(Color color){
        HelloBean helloBean = new HelloBean();
        helloBean.setColor(color);
        // list 集合  省略
        return helloBean;
    }

}
